<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
	public $helpers = array(
			'Paginator' => array('className' => 'PaginatorCustom'),
			'Html', 'Form', 'Session', 'Js'
		);	
	public $components = array(
			'Session',  'RequestHandler',
			'Auth' => array(
				//'loginAction' => array('controller' => 'users', 'action' => 'login'),
					'loginRedirect' => array('controller' => 'unidades', 'action' => 'index'),
					'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
				//	'authorize' => array('Controller')
			)
	);
	
	function beforeFilter() {
//		 $this->Auth->allow('*');
		$this->Auth->allow('users/login');
		
		if($this->Session->read('Auth.User.User.admin') !=1){
			$this->Auth->deny(array('users/add', 'users/edit', 'users/delete'));
		}
		
	}
	/* public $components = array(
			'Acl',
			'Auth' => array(
					'authorize' => array(
							'Actions' => array('actionPath' => 'Controllers'),
							'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
							'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
					)
			),
			'Session', 'RequestHandler'
	);
	public $helpers = array('Html', 'Form', 'Session', 'Js');
	
	function beforeFilter() {
		// $this->Auth->authorize = 'Controller';
		 $this->Auth->authorize = array(
		 		'Actions' => array('actionPath' => 'controllers/'),
		 		'Controller'
		 );
		/*$this->Auth->authError= 'You need permissions to access this page';
		$this->Auth->allow('users');
		$this->set('Auth',$this->Auth);
		$userdetails = $this->Auth->user();
		$this->Auth->allow('index', 'view');
	}
	/*public $helpers = array('Session', 'Html', 'Form', 'Js');
	public $components = array('Session', 'RequestHandler');*/
	
	
	/*public function beforeFilter() {
		//Configure AuthComponent
		/*$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
		$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
		$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
	}
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow('add'); // Letting users register themselves
	}
	
	public function login() {
		if ($this->Auth->login()) {
			$this->redirect($this->Auth->redirect());
		} else {
			$this->Session->setFlash(__('Invalid username or password, try again'));
		}
	}
	
	public function logout() {
		$this->redirect($this->Auth->logout());
	} */
//	public function isAuthorized($user) {
//		return true;
//	}
}
